import axios from "axios";


// 模拟数据 打包部署的时候 注释掉
// import '../mock/user';
import { useSelector } from "react-redux";



const ip = '192.168.101.41'; 

export const minioUrl = `http://${ip}:9000`

export const IM_SERVER_URL = `ws://${ip}:3000/websocket`;

export const baseURL = `http://${ip}:8881`;

export const getFile = (name:string) => {
    const str = localStorage.getItem("user");
    if (str) {
        const { token, user } = JSON.parse(str);
        return `${minioUrl}/im-server/${user.userId}/${name}`
    }

}

const instance = axios.create({
    baseURL: baseURL,
})


instance.interceptors.request.use((request) => {
    const userStr = localStorage.getItem("user")
    if (userStr) {
        const { token, user } = JSON.parse(userStr);
        if (token && user) {
            request.headers['Authorization'] = `${token}`;
        }
    }

    return request;
})

instance.interceptors.response.use((res): any => {
    return res.data;
}, err => {
    console.log(err);
})
export default instance;